import mitt from "mitt";
const EventBus = mitt();
export default EventBus;
export const SHOW_MSG = 'show_msg';
export const DATA_LOADED = 'data_loaded';

export const SHOW_LOADING = 'show_loading';
export const HIDE_LOADING = 'hide_loading';
export const CHANGE_LOAD_LOADING_TIP = 'change_loading_tip';

export const SHOW_CONFIRM = 'show_confirm';

export function showAlert(msg: string, title?: string) {
    EventBus.emit(SHOW_MSG, { msg, title });
}

export function showConfirm(msg: string, callback: (confirm: boolean) => void, title?: string) {
    EventBus.emit(SHOW_CONFIRM, { msg, callback, title });
}

export function showLoading(keepLoadingTip?: boolean) {
    EventBus.emit(SHOW_LOADING, keepLoadingTip);
}

export function hideLoading() {
    EventBus.emit(HIDE_LOADING);
}

export type AlertMessage = {
    title?: string,
    msg: string
}

export type ConfirmMessage = {
    title?: string,
    msg: string,
    callback: (confirm: boolean) => void;
}